using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace MinoChat.Converters;

/// <summary>
/// 将消息内容转换为 IsPlaying 布尔值
/// Content 为空时返回 true（正在播放动画）
/// Content 不为空时返回 false（显示静止状态）
/// </summary>
public class IsProcessingConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        // value 是 Content 属性的值（字符串）
        string? content = value as string;
        bool isProcessing = string.IsNullOrEmpty(content);

        // 如果目标类型是 Visibility，返回 Visibility 枚举
        if (targetType == typeof(Visibility))
        {
            return isProcessing ? Visibility.Visible : Visibility.Collapsed;
        }

        // 否则返回布尔值（用于 IsPlaying 绑定）
        return isProcessing;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

/// <summary>
/// IsProcessingConverter 的反转版本
/// Content 不为空时返回 true
/// </summary>
public class IsNotProcessingConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        string? content = value as string;
        bool isNotProcessing = !string.IsNullOrEmpty(content);

        if (targetType == typeof(Visibility))
        {
            return isNotProcessing ? Visibility.Visible : Visibility.Collapsed;
        }

        return isNotProcessing;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}
